package System_code;

import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-08-10
 * Time: 11:07
 */
public class Demo27 {

    public static void main(String[] args) throws InterruptedException {
        System.out.println("比赛开始");
        CountDownLatch latch=new CountDownLatch(10);
        Runnable runnable=new Runnable() {

            @Override
            public void run() {
                try {

                    Thread.sleep(1000);
                    latch.countDown();//任务执行完毕，调用 latch.countDown() . 在 CountDownLatch 内部的计数器同时自减.
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        for(int i=0;i<10;i++){
            new Thread(runnable).start();
        }
        //必须等待10个人比赛结束
        latch.await();
        System.out.println("比赛结束");
    }
}
